package assetservicelogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"
)

type AccountBindingEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAccountBindingEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AccountBindingEditLogic {
	return &AccountBindingEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改绑定
func (l *AccountBindingEditLogic) AccountBindingEdit(in *property_service.AccountBinding) (*property_service.Response, error) {
	m := query.Use(l.svcCtx.Gorm).AccountBinding
	_, err := m.WithContext(l.ctx).
		Where(m.ID.Eq(in.ID)).
		UpdateColumns(&model.AccountBinding{
			Code:               in.Code,
			Name:               in.Name,
			ClassificationCode: in.ClassificationCode,
			ClassificationName: in.ClassificationName,
			SubjectCode1:       in.SubjectCode1,
			SubjectName1:       in.SubjectName1,
			SubjectCode2:       in.SubjectCode2,
			SubjectName2:       in.SubjectName2,
			SubjectCode3:       in.SubjectCode3,
			SubjectName3:       in.SubjectName3,
			Remark:             in.Remark,
			UpdatedAtuser:      in.UpdatedAtuser,
		})
	if err != nil {
		return result.Err(err).Ed()
	}
	return result.Suc().EditEd()
}
